package com.java.business.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java.business.dao.ChapterDao;
import com.java.common.utils.PageUtils;
import com.java.business.entity.Chapter;
import com.java.business.service.ChapterService;
import com.java.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("chapterService")
public class ChapterServiceImpl extends ServiceImpl<ChapterDao, Chapter> implements ChapterService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<Chapter> page = this.page(
                new Query<Chapter>().getPage(params),
                // 拼接查询条件
                new LambdaQueryWrapper<Chapter>()
                        .eq(params.get("courseId") != null && StrUtil.isNotBlank(String.valueOf(params.get("courseId"))), Chapter::getCourseId, String.valueOf(params.get("courseId")))
        );

        return new PageUtils(page);
    }

}